package logic

import (
	"collect/model/mysql"
	"context"

	"collect/collectrpc/collectrpc"
	"collect/collectrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *collectrpc.ListRequest) (*collectrpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var users []mysql.User
	mysql.DB.Debug().Where("id  = ?", in.Id).Find(&users)
	var ListStruct []*collectrpc.ListStruct
	for _, user := range users {
		list := &collectrpc.ListStruct{
			Tel:      user.Tel,
			Password: user.Password,
		}
		ListStruct = append(ListStruct, list)
	}
	return &collectrpc.ListResponse{List: ListStruct}, nil
}
